package com.xpertline.ui.config;

import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import com.mimi.entity.Company;
import com.mimi.util.ConfigProvider;
import com.xpertline.ui.factory.DelButtonFactory;
import com.xpertline.ui.factory.SaveButtonFactory;
import com.xpertline.ui.factory.JTabbedPaneFactory;

public class ConfigPane extends JPanel {

	/**
	 * Create the panel.
	 */
	public ConfigPane() {
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{725, 0};
		gridBagLayout.rowHeights = new int[]{40, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		JTabbedPane tabbedPane =  JTabbedPaneFactory.createJTabbedPane();
		GridBagConstraints gbc_tabbedPane = new GridBagConstraints();
		gbc_tabbedPane.insets = new Insets(0, 0, 5, 0);
		gbc_tabbedPane.fill = GridBagConstraints.BOTH;
		gbc_tabbedPane.anchor = GridBagConstraints.NORTHWEST;
		gbc_tabbedPane.gridx = 0;
		gbc_tabbedPane.gridy = 1;
		add(tabbedPane, gbc_tabbedPane);
		final Component compayPane = new CompanyPane();
		Component moneyPane = new MoneyPane();
		Component pointPane = new PointPane();
		Component websitePane = new WebsitePane();
		
		tabbedPane.add(compayPane, "Thông tin công ty");
		tabbedPane.add(moneyPane, "Thiết lập giá tiền");
		tabbedPane.add(pointPane, "Thiết lập điểm thưởng");
		tabbedPane.add(websitePane, "Thiết lập site");
		
		JPanel panel = new JPanel();
		GridBagConstraints gbc_panel = new GridBagConstraints();
		gbc_panel.insets = new Insets(0, 0, 5, 0);
		gbc_panel.fill = GridBagConstraints.BOTH;
		gbc_panel.gridx = 0;
		gbc_panel.gridy = 0;
		add(panel, gbc_panel);
		
		JButton btnNewButton_1 = DelButtonFactory.createDeleteJButton();
		
		JButton btnNewButton = SaveButtonFactory.createSaveJButton();
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Company company = ((CompanyPane)compayPane).getCompany();
				ConfigProvider.getInstance().getDaoHelper().getDao(Company.class).saveOrUpdate(company);
			}
		});
		panel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
		panel.add(btnNewButton_1);
		panel.add(btnNewButton);
		
		Component verticalStrut = Box.createVerticalStrut(20);
		GridBagConstraints gbc_verticalStrut = new GridBagConstraints();
		gbc_verticalStrut.gridx = 0;
		gbc_verticalStrut.gridy = 2;
		add(verticalStrut, gbc_verticalStrut);
	}

}
